export default {
    name: "place_box",
    data() {
        return {
            new_address_id: {
                province: '',
                city: '',
                area: '',
            },
            provincesList: [],
            citiesList: [],
            areasList: [],
            new_address: {
                province: '',
                city: '',
                area: '',
                detail: ''
            },
        }
    },
    created() {
        this.getProvince()
    },
    methods: {
        async getProvince() {
            const { data: res } = await this.$http.get('/gim/api/user/getAllProvinces');
            this.provincesList = res.response
        },
        async getCity() {
            const { data: res } = await this.$http.post('/gim/api/user/getCities/' + this.new_address_id.province);
            this.citiesList = res.response
        },
        async getArea() {
            const { data: res } = await this.$http.post('/gim/api/user/getAreas/' + this.new_address_id.city);
            this.areasList = res.response
        },
        getAddress(id, value) {
            if (id == '1') {
                this.new_address.province = value
            }
            if (id == '2') {
                this.new_address.city = value
            }
            if (id == '3') {
                this.new_address.area = value
            }

            const address = this.new_address.province + this.new_address.city + this.new_address.area + this.new_address.detail
            this.$store.commit('edit_address', address)
        },
    },
}